#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Solution {
public:
	int addDigits(int num) {
		int res=num%10;
		num=num/10;
		while (num!=0)
		{
			int tmp=num%10;
			num=num/10;
			res+=tmp;
			if (res>9)
				res=res/10+res%10;
		}
		return res;
	}
};

int main()
{
	Solution s;
	int n;
	while(true)
	{
		cin>>n;
		cout<<s.addDigits(n)<<endl;
	}
	return 0;
}